﻿Public Class frmQuanLyDonVi
    Dim da As DataProvider
    Public Sub LoadDS()
        Dim sql = "select * from DONVI"
        da = New DataProvider
        dgvDanhSachDonVi.DataSource = da.ShowData(sql)
    End Sub
    Private Sub frmQuanLyDonVi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDS()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim sql = "insert into DONVI values('" + txtMaDonVi.Text + "','" + txtTenDonVi.Text + "')"
        da = New DataProvider
        da.SqlExcuteNonQuery(sql)
        LoadDS()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim sql = "delete from DONVI where MaDV = '" + txtMaDonVi.Text + "'"
        da = New DataProvider
        da.SqlExcuteNonQuery(sql)
        LoadDS()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim sql = "update DONVI set TenDV = N'" + txtTenDonVi.Text + "' where MaDV = '" + txtMaDonVi.Text + "'"
        da = New DataProvider
        da.SqlExcuteNonQuery(sql)
        LoadDS()
    End Sub

    Private Sub dgvDanhSachDonVi_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvDanhSachDonVi.SelectionChanged
        txtMaDonVi.Text = dgvDanhSachDonVi.CurrentRow.Cells(0).Value.ToString()
        txtTenDonVi.Text = dgvDanhSachDonVi.CurrentRow.Cells(1).Value.ToString()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Close()
    End Sub
End Class